package com.flyway.execise.flyway_db;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


/**
 * @date 19-7-17
 * @auther jackliang
 * @description TODO
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {


    public  ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext=applicationContext;


        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        Class<?> cls = null;
        try {
            cls = loader.loadClass("com.flyway.execise.flyway_db.Controller");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
//        AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
//        Object val  = factory.createBean(cls,1,true);
//        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory)factory;
//        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(cls);
//        beanDefinitionBuilder.setAutowireMode(1);
//        beanDefinitionBuilder.setDependencyCheck(0);
////        defaultListableBeanFactory.registerBeanDefinition("controller",beanDefinitionBuilder.getBeanDefinition());
//        BeanDefinition beanDefinition= defaultListableBeanFactory.getBeanDefinition("controller");
    }
}
